#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; ++i)
using namespace std;
const int N = 5;
char a[N][N], ans[N][N];
vector<pair<int, int>> v[4];
int flag;
bool used[5];
bool chk() {
  // line
  rep(i, 1, 3) {
    rep(k, 1, 3) used[k] = 0;
    rep(j, 1, 3) {
      int x = a[i][j] - '0';
      if (used[x]) return 0;
      used[x] = 1;
    }
  }

  // row
  rep(j, 1, 3) {
    rep(k, 1, 3) used[k] = 0;
    rep(i, 1, 3) {
      int x = a[i][j] - '0';
      if (used[x]) return 0;
      used[x] = 1;
    }
  }

  rep(b, 1, 3) {
    rep(k, 1, 3) used[k] = 0;
    for (auto [u, v] : v[b]) {
      int x = a[u][v] - '0';
      if (used[x]) return 0;
      used[x] = 1;
    }
  }
  return 1;
}
vector<pair<int, int>> em;
int len;
void dfs(int p) {
  if (p == len) {
    if (chk()) {
      ++flag;
      rep(i, 1, 3) rep(j, 1, 3) ans[i][j] = a[i][j];
    }
    return;
  }
  if (flag >= 2) return;
  rep(i, 1, 3) {
    int x = em[p].first, y = em[p].second;
    a[x][y] = i + '0';
    dfs(p + 1);
  }
}
void solve() {
  flag = 0;
  em.clear();
  rep(i, 1, 3) cin >> a[i] + 1;
  rep(i, 1, 3) v[i].clear();
  int x, y;
  rep(i, 1, 3) {
    rep(j, 1, 3) {
      cin >> x >> y;
      ++x, ++y;
      v[i].emplace_back(x, y);
      if (a[i][j] == '*') em.emplace_back(i, j);
    }
  }
  len = em.size();
  dfs(0);
  if (flag == 1) {
    cout << "Unique\n";
    rep(i, 1, 3) cout << ans[i] + 1 << '\n';
  } else if (flag == 0)
    cout << "No\n";
  else
    cout << "Multiple\n";
}
int main() {
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
/*

4
*2*
1*2
***
0 0 0 1 1 0
0 2 1 1 1 2
2 0 2 1 2 2
**3
***
***
0 0 1 0 1 1
0 1 0 2 1 2
2 0 2 1 2 2
**3
1**
**2
0 0 1 0 1 1
0 1 0 2 1 2
2 0 2 1 2 2
3*3
1**
**2
0 0 1 0 1 1
0 1 0 2 1 2
2 0 2 1 2 2
*/
